<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
    <title></title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/css.css">

<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="<%=request.getContextPath()%>/ace/assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/ace/assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- text fonts -->
<!-- ace styles -->
<link rel="stylesheet" href="<%=request.getContextPath()%>/ace/assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<link rel="stylesheet" href="<%=request.getContextPath()%>/static/alert/jquery-confirm.min.css" />
<!--[if !IE]> -->
<script src="<%=request.getContextPath()%>/ace/assets/js/jquery-2.1.4.min.js"></script>

<!-- <![endif]-->
<script src="<%=request.getContextPath()%>/static/alert/jquery-confirm.min.js"></script>
</head>
<body>
	
	<div class="breadcrumbs" id="breadcrumbs">

		<c:if test="${not empty msg}">
			<div id="myAlert" class="alert alert-warning">
				<a href="#" class="close" data-dismiss="alert">&times;</a>
				<strong>警告！</strong>${msg }。
			</div>
		</c:if>
		<!-- /.breadcrumb -->

	</div>

	<!-- /section:basics/content.breadcrumbs -->
	<div class="page-content">
		<!-- /section:settings.box -->
		<div class="page-content-area">
			<div class="page-header">
				<h1>
					部门管理
				</h1>
			</div>
			<!-- /.page-header -->

			<div class="row">
				<div class="col-xs-12">
					<!-- PAGE CONTENT BEGINS -->
						    <form:form id="form" method="post" class="form-horizontal" commandName="organization">
						        <form:hidden path="id"/>
						        <form:hidden path="available"/>
						        <form:hidden path="parent_id"/>
						        <form:hidden path="parent_ids"/>
						
						        <div class="form-group">
						            <form:label path="name" class="col-sm-2 control-label">名称：</form:label>
						            <div class="col-sm-10">
						            	<form:input path="name" class="form-control"/>
						            </div>
						        </div>
						        <div class="btn-group col-sm-offset-2">
							        <shiro:hasPermission name="organization:update">
							            <form:button id="updateBtn" class="btn btn-default">修改</form:button>
							        </shiro:hasPermission>
							
							        <shiro:hasPermission name="organization:delete">
							            <c:if test="${not organization.rootNode}">
							            <form:button id="deleteBtn" class="btn btn-default">删除</form:button>
							            </c:if>
							        </shiro:hasPermission>
							
							        <shiro:hasPermission name="organization:create">
							            <form:button id="appendChildBtn" class="btn btn-default">添加子节点</form:button>
							        </shiro:hasPermission>
							
							        <shiro:hasPermission name="organization:update">
							            <c:if test="${not organization.rootNode}">
							            <form:button id="moveBtn" class="btn btn-default">移动节点</form:button>
							            </c:if>
							        </shiro:hasPermission>
								</div>
						    </form:form>

					<!-- PAGE CONTENT ENDS -->
				</div>
				<!-- /.col -->
			</div>
			<!-- /.row -->
		</div>
		<!-- /.page-content-area -->
	</div>
	<!-- /.page-content -->


    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.0.min.js"></script>
    <script>
        $(function() {
            $("#updateBtn").click(function() {
                $("#form")
                        .attr("action", "${pageContext.request.contextPath}/organization/${organization.id}/update")
                        .submit();
                return false;
            });
            $("#deleteBtn").click(function() {
                if(confirm("确认删除吗？")) {
                    $("#form")
                            .attr("action", "${pageContext.request.contextPath}/organization/${organization.id}/delete")
                            .submit();
                }
                return false;
            });

            $("#appendChildBtn").click(function() {
                location.href="${pageContext.request.contextPath}/organization/${organization.id}/appendChild";
                return false;
            });

            $("#moveBtn").click(function() {
                location.href="${pageContext.request.contextPath}/organization/${organization.id}/move";
                return false;
            });
        });
    </script>
</body>
</html>